package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductService;
import com.atguigu.spzx.model.entity.system.Product;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "商品管理")
@RestController
@RequestMapping("/admin/product/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/{page}/{limit}")
    @Operation(summary = "分页")
    public Result<PageInfo<Product>> pageInfo(@PathVariable Integer page , @PathVariable Integer limit,Product product)
    {
        PageInfo<Product> pageInfo = productService.findAll(page,limit,product);
        return Result.OK(pageInfo);
    }

    @PostMapping("/save")
    @Operation(summary = "新增商品")
    public Result save (@RequestBody Product product){
        productService.save(product);
        return Result.OK();
    }

    @DeleteMapping("/{id})")
    @Operation(summary = "删除商品")
    public Result removeById (@PathVariable Integer id){
        productService.remove(id);
        return Result.OK();
    }

    @PutMapping("/updateStatus/{id}/{status}")
    @Operation(summary = "修改商品状态")
    public Result updatestatus (@PathVariable Integer id, @PathVariable Integer status){
        productService.updatestatus(id,status);
        return Result.OK();
    }

    @PutMapping("/updateAuditStatus/{id}/{auditstatus}")
    @Operation(summary = "修改审核状态")
    public Result updateAuditStatus (@PathVariable Integer id , @PathVariable Integer auditstatus){
        productService.updateAuditStatus(id,auditstatus);
        return Result.OK();
    }

    @PutMapping("/updateById")
    @Operation(summary = "根据id修改商品")
    public Result updateById(@Parameter(name = "product", description = "请求参数实体类", required = true) @RequestBody Product product){
        productService.updateById(product);
        return Result.OK();
    }
}
